using NUnit.Framework;
using Tycho.Parser.Peg;

namespace Tycho.Parser.Tests.Peg {
    [TestFixture]
    public class StringProductionSpecification {
        [Test]
        public void ShouldParseSimpleTerminatedString () {
            var s = StringProduction.CreateTerminal();

            ParseResult result = s.Parse ("'abc'", 0, new ParseContext ());
            Assert.IsNotNull (result);
            Assert.AreEqual(5, result.Index);
            var term = result.Term as StringTerm;
            Assert.IsNotNull (term);
            Assert.AreEqual ("abc", term.Value);
            Assert.AreEqual (new SourceInformation (null, 0, 5), result.Term.SourceInformation);
        }

        [Test]
        public void ShouldParseSimpleStringWithSingleQuote () {
            var s = StringProduction.CreateTerminal();

            ParseResult result = s.Parse ("'ab''c'", 0, new ParseContext ());
            Assert.IsNotNull (result);
            Assert.AreEqual(7, result.Index);
            var term = result.Term as StringTerm;
            Assert.IsNotNull (term);
            Assert.AreEqual ("ab'c", term.Value);
            Assert.AreEqual (new SourceInformation (null, 0, 7), result.Term.SourceInformation);
        }

        [Test]
        public void ShouldNotParseUnterminatedString () {
            var s = StringProduction.CreateTerminal();

            ParseResult result = s.Parse ("'abc", 0, new ParseContext ());
            Assert.IsNull (result);
        }

        [Test]
        public void ShouldNotParseUnterminatedStringAtQuote () {
            var s = StringProduction.CreateTerminal();

            ParseResult result = s.Parse ("'abc''", 0, new ParseContext ());
            Assert.IsNull (result);
        }
    }
}